package com.daye.dao;

import com.daye.entity.Phone;
import com.daye.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class PhoneDao {

    //查询价格高于2000元，生产日期是2019年之前的所有手机
    public List<Phone> getPhoneTestOne(double price , String date) throws SQLException {
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        String sql = "SELECT * FROM phone WHERE price > ? AND prodate < ?";
        return qr.query(sql , new BeanListHandler<Phone>(Phone.class) , price , date);
    }

    /**
     * 查询所有颜色是白色的手机信息
     * @param color
     * @return
     */
    public List<Phone> getPhoneTestTwo(String color) throws SQLException {
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        String sql = "SELECT * FROM phone WHERE color = ?";
        return qr.query(sql , new BeanListHandler<Phone>(Phone.class) , color);
    }
}
